import jmespath
from requests import delete

from basic.base import BaseRequest

class URL:
    label_create_url = "adminapi/member/label"
    label_delete_url = "adminapi/member/label"
    label_update_url = "adminapi/member/label"
    label_list_url = "adminapi/member/label"

class MemberLabel(BaseRequest,URL):
    def label_create(self,label_name):
        data = {
            "label_id": "",
            "label_name": label_name,
            "memo": "",
            "sort": 0
            }
        return self.post(self.label_create.__name__,self.label_create_url,data=data)

    def label_delete(self,delete_id):
        return self.delete(self.label_delete.__name__,self.label_delete_url+f"/{delete_id}")


    def label_update(self,label_id,label_name,memo ="",sort=0):
        params = {"label_id":label_id,"label_name":label_name,"memo":memo,"sort":sort}
        return self.get(self.label_update.__name__, self.label_update_url+f"/{label_id}",params=params)

    def label_list(self,label_name = ""):
        params = {
            "page":1,
            "limit":10,
            "label_name": label_name
            }
        return self.get(self.label_list.__name__,self.label_list_url, params=params)


if __name__ == '__main__':
    member_label = MemberLabel()
    member_label.label_create()
    member_label.label_update()
    member_label.label_list()
    data = member_label.label_list()
    id_list = jmespath.search("data.data[*].label_id",data)
    for i in id_list:
        member_label.label_delete(i)

